﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using Bll;
using Newtonsoft.Json;
namespace WebApiServer.Controllers
{
    public class MenuController : ApiController
    {
        MenuBll bll = new MenuBll();


        #region 显示全部菜品
        public List<Menu> Getshow()
        {
            return bll.Menushow();
        }

        #endregion

        #region 根据id 查询菜品
        public List<Menu> GetshowByid(int id)
        {
            List<Menu> list = bll.Menushow();
            list = list.Where(p => (p.MenuId == id)).ToList();
            return list;
        }
        #endregion

        #region 菜单分类
        /// <summary>
        /// 菜单分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<Menu> GetMenutype(int id)
        {
            return bll.menutype(id);
        
        }
        #endregion

        #region 选中的菜品
        /// <summary>
        /// 添加购物车
        /// </summary>
        /// <param name="jia"></param>
        /// <returns></returns>
        public string GetMenuIdshow(int id)
        {
            return JsonConvert.SerializeObject(bll.carshow(id));
        }

        #endregion

        #region 添加到购物车
        public int getaddcar(int CarId, string CarName, string CarPhoto, string CarDescrib, decimal CarPrice, int CarNum, int UserId)
        {



            int i = bll.addcar(CarId, CarName, CarPhoto, CarDescrib, CarPrice, CarNum, UserId);
            if (i == 1)
            {
                return 1;//修改

            }
            else if (i == 2)
            {

                return 2;//添加
            }
            else
            {
                return 0;//

            }
        
        }
        #endregion

        #region 管理员删除菜单
        /// <summary>
        /// 删除菜单信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Getdelete(int id)
        {
            return bll.delete(id);
        }

        #endregion

        #region 修改菜单
          /// <summary>
       /// 修改菜单
       /// </summary>
       /// <param name="gai"></param>
       /// <returns></returns>


        public int getupdate(string MenuName, string MenuPhoto, string MenuDescrib, string MenuPrice, int MenuId)
        {

            if (bll.update(MenuName, MenuPhoto, MenuDescrib, MenuPrice, MenuId) > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }

        #endregion

        #region 添加菜品
        ///添加
        public int PostaddMen(Menu n)
        {
            if (bll.addMen(n) > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        #endregion






    }
}



